package  com.syqc.sensor.water

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.syqc.custom.LeftRightTextView
import com.syqc.entity.OilDay
import com.syqc.monitor.R
import com.syqc.utils.Units

class WaterInfoAdapter : BaseQuickAdapter<OilDay, BaseViewHolder>(R.layout.item_sensor_water_info) {
    var precision: String = "2"
    var unit: String = ""

    init {
        addChildClickViewIds(R.id.iv_water_info_pop, R.id.lr_tv_water_add_times)
    }

    override fun convert(holder: BaseViewHolder, item: OilDay) {
        holder.run {
            val position = holder.layoutPosition + 1
            val num = if (position < 10) "0$position" else "$position"

            val mileStr = if (item.mile > 1000) {
                "${item.mileKm} ${Units.km}"
            } else {
                "${item.mileKm} ${Units.m}"
            }

            holder.setText(R.id.tvItemNum, num)
            holder.getView<LeftRightTextView>(R.id.lr_tv_water_sensor_time).setRightText(item.day)
            holder.getView<LeftRightTextView>(R.id.lr_tv_water_add_total)
                .setRightText("${item.upTotal} $unit")
            val addWater = holder.getView<LeftRightTextView>(R.id.lr_tv_water_add_times)
            addWater.nextVisible(item.upTimes > 0)
            addWater.setRightText("${item.upTimes} ${context.getString(R.string.unit_num)}")
            holder.getView<LeftRightTextView>(R.id.lr_tv_water_leak_total)
                .setRightText("${item.downTotal}  $unit")
            holder.getView<LeftRightTextView>(R.id.lr_tv_water_run_mile)
                .setRightText(mileStr)
        }
    }
}